<?php

require_once("db_functions.php");
require_once("functions.php");
require_once("xml.class.php");

class ugovori_fakture extends page{
	
	var $db;
	
	var $beginelements = array(
		
	);
	var $endelements = array(
	);
	
	function ugovori_fakture(){
		$this->db = new db_functions();
	}
	
	function import(){
		
		$back = "up.php?af=afterUploadFakture&amp;ft=xml";
		
		$this->assign("afterfunc","afterUploadFakture");
		$this->assign("filetype","xml");
		$this->assign("back_uri",urlencode($back));
		echo $this->parseTemplate("ugovori/fakture/import.tpl");
	}
	function displayImportedFile(){
		$fn = getFromInput("fn");
		if (!file_exists($fn)) {
			die("Fajl $fn ne postoji.");
		}
		$xml = new xml_yp($fn);
		
		$xml->parse();
		
		$fields = array(
			"fd_ir_tip_id",
			"datum_isporuke",
			"iznos_pdv_opsta_stopa",
			"iznos_pdv_posebna_stopa",
			"spoljni_broj"
		);
		
		$ret = $xml->get_elements($fields);
		//print_rarray($ret);
		foreach ($ret[$fields[0]] as $k=>$v){
			echo "<p>";
			echo $fields[0].": ".$v["value"]."<br />";
			echo $fields[1].": ".$ret[$fields[1]][$k]["value"]."<br />";
			echo $fields[2].": ".$ret[$fields[2]][$k]["value"]."<br />";
			echo $fields[3].": ".$ret[$fields[3]][$k]["value"]."<br />";
			echo $fields[4].": ".$ret[$fields[4]][$k]["value"]."<br />";
			echo "</p>";
		}
	}
}

?>